home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / D-G / FORTRAN Goodies / String Utilities / LTRIM.f < prev    next >
Encoding:
Text File  |  1990-12-05  |  1.2 KB  |  64 lines  |  [TEXT/MPS ]

  1. C    This example Trims blanks off the front of a character.
  2. C
  3. C      Function LTRIM - 
  4. C
  5. C        Takes a string or a character as input.
  6. C
  7. C        Returns a Pascal-type string as a result.
  8. C
  9. C
  10. C    Example provided for owners of Language Systems FORTRAN
  11. C    © 1990 Language Systems Corp.
  12. C
  13. C    Written by Steven Hopkins
  14. C
  15.     string function LTRIM(Char_Str_Arg)
  16.  
  17. C         receive the argument by Descriptor
  18.  
  19.     structure /DescRec/
  20.         pointer /character*1/ DataPtr
  21.         integer*2 DataSize
  22.         integer*2 SymT
  23.     end structure
  24.     record /DescRec/ Char_Str_Arg
  25.  
  26. C         Local Declarations
  27.  
  28.     integer*4 chard,strngd
  29.     parameter (chard=18,strngd=19)
  30.     pointer /character*1/ Char_Str_Ptr
  31.     integer*4 size, count
  32.  
  33. C         point to the character argument
  34.  
  35.     Char_Str_Ptr = Char_Str_Arg.DataPtr
  36.  
  37. C         Decide if Argument is a Character or String 
  38. c        and store the size
  39.  
  40.     if (Char_Str_Arg.SymT = strngd) then
  41.         size = MIN(255,ichar(Char_Str_Ptr^))
  42.         Char_Str_Ptr = Char_Str_Ptr + 1
  43.     else
  44.         size = MIN(Char_Str_Arg.DataSize,255)
  45.     end if
  46.  
  47. C        count the number of blanks
  48.  
  49.     count = 0
  50.     do while ((count < size) .and. (Char_Str_Ptr^ = ' '))
  51.         Char_Str_Ptr = Char_Str_Ptr + 1
  52.         count = count + 1
  53.     end do
  54.  
  55. C        return the trimmed argument
  56.  
  57.     if (count < size) then
  58.         LTRIM = Char_Str_Ptr^(1:(size-count))
  59.     else
  60.         LTRIM = ''
  61.     end if
  62.     
  63.     end
  64.